using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraEditors;

namespace PhongKham.View
{
    public partial class frmDmThuoc : PhongKham.FrmTemplate
    {
        DataSet dsDmThuoc = new DataSet();
        PhongKham.Controller.DmThuocController control = new PhongKham.Controller.DmThuocController();
        public StatusEnum mode = StatusEnum.KhởiTạo;
        public frmDmThuoc()
        {
            InitializeComponent();
            
            btnAdd.Visibility = DevExpress.XtraBars.BarItemVisibility.Always;
            btn_Save.Visibility = DevExpress.XtraBars.BarItemVisibility.Never;
            //gridControl1.DataMember = "";
            DisplayInfo();
        }

        public void DisplayInfo()
        {
            dsDmThuoc = control.GetAll();
            gridControl1.DataSource = dsDmThuoc.Tables[0];
        }

        public void Cleardata()
        {
            txtMaThuoc.Text = String.Empty;
            txtTenThuoc.Text = String.Empty;
            txtTenBietDuoc.Text=String.Empty;
            cboDonVi.SelectedIndex = 0;
            txtGhiChu.Text = String.Empty;
        }

        public void ChangedStatus()
        {
            if (mode == StatusEnum.Thêm || mode == StatusEnum.Sửa)
            {
                btnAdd.Visibility = DevExpress.XtraBars.BarItemVisibility.Never;
                btnUpdate.Visibility = DevExpress.XtraBars.BarItemVisibility.Never;
                btnDel.Visibility = DevExpress.XtraBars.BarItemVisibility.Never;
                btn_Save.Visibility = DevExpress.XtraBars.BarItemVisibility.Always;
                btnRevert.Visibility = DevExpress.XtraBars.BarItemVisibility.Always;
                
            }
            else if (mode == StatusEnum.BỏQua || mode == StatusEnum.Lưu)
            {
                btnAdd.Visibility = DevExpress.XtraBars.BarItemVisibility.Always;
                btn_Save.Visibility = DevExpress.XtraBars.BarItemVisibility.Never;
                btnRevert.Visibility = DevExpress.XtraBars.BarItemVisibility.Never;
            }
        }

        public override void PerformAdd()
        {
           
            mode = StatusEnum.Thêm;
            ChangedStatus();
        }

        public override void PerformUpdate()
        {
            mode = StatusEnum.Sửa;
            ChangedStatus();
        }

        public override void PerformSave()
        {
            if (mode == StatusEnum.Thêm)
            {

            }
            else if (mode == StatusEnum.Sửa)
            {
            }
            
            Cleardata();
            DisplayInfo();
            mode = StatusEnum.Lưu;
            ChangedStatus();
        }

        public override void PerformDel()
        {
          
        }

        public override void PerformRevert()
        {
            Cleardata();
            mode = StatusEnum.BỏQua;
            ChangedStatus();
        }

        private void gvThuoc_Click(object sender, EventArgs e)
        {
            if (gvThuoc.RowCount > 0)
            {
                btnUpdate.Visibility = DevExpress.XtraBars.BarItemVisibility.Always;
                btnDel.Visibility = DevExpress.XtraBars.BarItemVisibility.Always;
            }
            //"" + gvThuoc.GetFocusedDataRow()[""];//lay du lieu dong hien tai
        }
    }
}